#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "channellist.h"
#include "player.h"
#ifdef Q_OS_MAC
#include "appleremote.h"
#endif

#include <QtGui/QMainWindow>
#include <QNetworkAccessManager>
#include <QProgressDialog>
#include <QTimer>

namespace Ui
{
    class MainWindow;
}

class ChannelList;
class Channel;
class Program;
class QModelIndex;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

public:
    void loadStyleSheets(const QStringList& sheets);
    Program* currentProgram() const;
    void setCurrentChannel(int channel);
    
private:
    void ensureDefaultSettings(bool reset = false);

public: // from QWidget
    void keyPressEvent(QKeyEvent* event);
    void closeEvent(QCloseEvent *event);
    void changeEvent(QEvent* event);

public slots:
    void authenticationRequired(QNetworkReply* reply, QAuthenticator* authenticator);
    void authenticationError();
    void updateChannelsIfNecessary();
    void updateChannels(bool force);
    void channelsUpdated(bool success);
    void showFocusedProgram();
    void loadCurrentThumbnail();
    void thumbnailReceived();
    void updateClock();
    void showMainMenu();
    void showProgramMenu();
    void showSettingsMenu();
    void showAllSettingsMenu();
    void toggleFullScreen();
    void startPlayback();
    void playbackFinished();
    void showMessage(const QString& message);
    void showProgressInfo(const QString& channelName, int channel, int numChannels);

private:
    Ui::MainWindow *ui;
    ChannelList* channels;
    int currentChannel;
    QNetworkAccessManager http;
    QTimer delayedThumbnailLoad;
    QTimer clockUpdater;
    bool authSent;
    Player player;
#ifdef Q_OS_MAC
    AppleRemote remote;
#endif
};

#endif // MAINWINDOW_H
